package cn.gson.boot.model.dao;

import cn.gson.boot.model.pojos.Huikuan;
import cn.gson.boot.model.pojos.Tuihuo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import javax.transaction.Transactional;

public interface TuiHuoDao extends CrudRepository<Tuihuo,Integer> {
   //移除退货
   @Transactional
   @Modifying(clearAutomatically = true)
   @Query(nativeQuery = true,value = "update tuihuo set th_ys=0 where th_id=?1")
    public void yichuTuiHuo(Integer thId);
   //删除退货
   @Transactional
   @Modifying(clearAutomatically = true)
   @Query(nativeQuery = true,value = "delete from tuihuo where th_id=?1")
   public void deleteTuiHuo(Integer thId);
    /*//根据合同id来移除合同 （逻辑删除）
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "update hetong set ht_ys=0 where ht_id=?1")
    public void yichuHeTong(Integer htid);*/

    //修改实退款
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "update tuihuo set th_shimoney= th_shimoney +?1 where th_id=?2")
    public void updatShiTuiKuan(double shituiKuan,Integer thId);

    //修改退货状态
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "update tuihuo set th_zhuangtai=?1 where th_id=?2")
    public void updateTuiHuoZt(String  zt,Integer thId);

    //审核
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "update tuihuo set th_sh=?1 where th_id=?2")
    public void shenheTuiHuo(String sh,Integer thid);

    //修改退货单入库的状态
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "update tuihuo set th_rk=?1 where th_id=?2")
    public void updateTuiHuoRuku(String thRk,Integer thId);

    //修改退货单维修完成的状态(-1=>没有,0=>维修中,1=>完成)
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "update tuihuo set th_wxwc=?1 where th_id=?2")
    public void updateTuiHuoWxwc(Integer wxwc,Integer thId);
}